
import { routerRedux } from 'dva/router';
import { stringify } from 'qs';
import { getRepairsList,updateCloseTipState,delRepair } from '@/services/http';

export default {
  namespace : 'RepairsList',
  state:{
    repairList:[
    ],
    total:0,
    isLoading:true
  },
  effects: {
    *getRepairsList(payload, { call, put }) {
      const response = yield call(getRepairsList,payload.payload);
      yield put({
        type: '_getRepairsList',
        data: response,
      });
    },

    *updateCloseTipState(payload, { call, put }) {
      const response1 = yield call(updateCloseTipState,payload.payload);
      const response2 = yield call(getRepairsList,payload.payload);

      yield put({
        type: '_getRepairsList',
        data: response2,
      });
    },

    * delRepair(payload, {call, put}) {
      const response1 = yield call(delRepair, payload.payload);
      const response2 = yield call(getRepairsList, payload.payload);
      yield put({
        type: '_getRepairsList',
        data: response2,
      });
    },

  },

  reducers:{
    _getRepairsList(state,action){
      return {
        ...state,
        repairList: action.data.code == 1 ? action.data.ret : [],
        total:action.data.code == 1 ?action.data.total : 0,
        isLoading:false
      }
    }
  }
}
